package com.shujia.day10;

/*
    String其它功能：
        替换功能
            String replace(char old,char new)
            String replace(String old,String new)
        去除字符串两空格
            String trim()
        按字典顺序比较两个字符串
            int compareTo(String str)
            int compareToIgnoreCase(String str)

 */
public class StringDemo7 {
    public static void main(String[] args) {
        String s1 = "dasqwajavadwqrajjavaiojadjavafq-aedjavaqajiqa";
        //String replace(char old,char new) 由新字符替换字符串中所有旧字符
        String res1 = s1.replace('a', '$');
        System.out.println(s1);
        System.out.println(res1);
        //String replace(String old,String new) 由新的字符串替换旧的字符串
        String res2 = s1.replace("java", "李刚");
        System.out.println(res2);
        //String trim() 去除字符串两边的空格
        String s2 = "    hello  world    ";
        System.out.println("s2: "+s2);
        String res3 = s2.trim();
        System.out.println("res3: "+res3);
        //int compareTo(String str) 按字典顺序比较两个字符串是否相同 当结果是0的时候表示两个字符串内容相同
        String s3 = "hello";
        String s4 = "world";
        String s5 = "hel";
        String s6 = "hello";
        System.out.println(s3.compareTo(s4)); // -15
        System.out.println(s3.compareTo(s5)); // 2
        System.out.println(s3.compareTo(s6)); // 0


    }
}
